package GUI;
import Pantallas.PantallaInicio;
import Pantallas.PantallaProducto;
import Pantallas.PantallaStatus;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;

/**
 * Button field with a bitmap as its label.
 */
public class BitmapButtonField extends ButtonField{
	//
	private int seleccion;
    private Bitmap bitmap;
    private Bitmap bitmapHighlight;
    private boolean highlighted = false;

    /**
     * Instantiates a new bitmap button field.
     * 
     * @param bitmap the bitmap to use as a label
     */
    public BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight,int opc) {
        this(bitmap, bitmapHighlight, ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER);
        this.seleccion = opc;
    }
    /**
     * 
     * @param bitmap
     * @param bitmapHighlight
     * @param style
     */
    private BitmapButtonField(Bitmap bitmap, Bitmap bitmapHighlight, long style) {
        super(style);
        this.bitmap = bitmap;
        this.bitmapHighlight = bitmapHighlight;
        
    }
    /**
     * 
     */
    protected void layout(int width, int height) {
            setExtent(getPreferredWidth(), getPreferredHeight());
    }
    /**
     * 
     */
    public int getPreferredWidth() {
            return bitmap.getWidth();
    }
    /**
     * 
     */
    public int getPreferredHeight() {
            return bitmap.getHeight();
    }
	/**
	 * 
	 */
    protected void paint(Graphics graphics) {
            super.paint(graphics);
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            Bitmap b = bitmap;
            if (highlighted)
                b = bitmapHighlight;
            graphics.drawBitmap(0, 0, width, height, b, 0, 0);
    }
    /**
     * 
     * @param highlight
     */
    public void setHighlight(boolean highlight)
    {
    	// this.highlighted = highlight;           
    }
    /**
     * 
     */
    protected boolean navigationClick(int status, int time) {
		// TODO Auto-generated method stub
		getPantalla();
		return true;
	}
    /**
     * 
     */
	protected boolean touchEvent( TouchEvent event ) 
	{
	   switch( event.getEvent()  ) 
	   {
	        case TouchEvent.CLICK:
	           //handle click event here
        		getPantalla();
	        return true;
	        case TouchEvent.DOWN:
	           //handle down event here 
	        return true;
	        case TouchEvent.MOVE:
	           //handle move event here
	        return true;
	   }
	   return false;
	}
	/**
	 * 
	 * @return
	 */
	private void getPantalla(){		
		switch(this.seleccion){
			case 0:
				PantallaInicio.iniciarSesion();				
			case 1:
				UiApplication.getUiApplication().pushScreen(new PantallaStatus());
			case 2:
				UiApplication.getUiApplication().pushScreen(new PantallaProducto());
			case 3:
				UiApplication.getUiApplication().pushScreen(new PantallaInicio());
		}
	}
}